package com.Hsu.book.mapper;

import com.Hsu.book.model.BookInfo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author Hsu琛君珩
 * @ClassName:BookInfoMapper
 * @date 2024-01-04
 * @apiNote
 * @Version: v1.0
 */

@Mapper
public interface BookInfoMapper {
    /**
     * 获取当前页信息
     * 选取状态不为0的记录，并且按照id降序排列
     * @param offset    要跳过的记录数
     * @param pageSize  每页显示的记录数
     * @return
     */
    @Select("select * from book_info where status!=0" +
            " order by id desc limit #{offset},#{pageSize}")
    List<BookInfo> selectBookInfoByPage(Integer offset,Integer pageSize);

    /**
     * 获取总记录数
     * 选取状态不为0的记录
     * @return
     */
    @Select("select count(1) from book_info where status!=0")
    Integer count();

    @Insert("insert into book_info(book_name,author,count,price,publish,status)" +
            " values(#{bookName},#{author},#{count},#{price},#{publish},#{status})")
    Integer insertBook(BookInfo bookInfo);

    @Select("select * from book_info where id=#{id}")
    BookInfo queryBookInfoById(Integer id);

    Integer updateBook(BookInfo bookInfo);

    Integer batchDelete(List<Integer> ids);
}
